package com.nulldev.util.manage.experiments;

import com.nulldev.util.JVM.Arguments;

public class Experiment {

	private final String url;
	private final String codeName;
	private final String description;
	private final String[] launchArguments;
	private final String configOption;

	Experiment() {
		this.url = null;
		this.codeName = null;
		this.description = null;
		this.configOption = null;
		this.launchArguments = null;
	}

	public Experiment(final String url, final String codeName, final String description, final String configOption, final String... arguments) {
		if (url == null || url.isEmpty())
			throw new NullPointerException("url == null!");
		if (codeName == null || description == null || configOption == null || arguments == null)
			throw new NullPointerException();
		if (!url.contains("://") || !url.endsWith("/"))
			throw new IllegalArgumentException("Invalid format for URL: " + url);
		this.url = url;
		this.codeName = codeName;
		this.description = description;
		this.configOption = configOption;
		this.launchArguments = arguments;
	}

	public String url() {
		return this.url;
	}

	public String codeName() {
		return this.codeName;
	}

	public String description() {
		return this.description;
	}

	public String configOption() {
		return this.configOption;
	}

	public String[] arguments() {
		return this.launchArguments;
	}

	private boolean active;

	public boolean isActive() {
		// TODO: Integrate global configuration files.
		if (this.active)
			return this.active;
		return Arguments.hasArgument(this.launchArguments);
	}

	protected Experiment setActive(final boolean state) {
		this.active = state;
		return this;
	}
}
